Skip to content

fix: normalize provider-prefixed model names in extractModel()#24

Open
sven-ea-assistant wants to merge 2 commits intoatalovesyou:mainfrom
sven-ea-assistant:fix/issue-23-model-prefix-routing
Open

fix: normalize provider-prefixed model names in extractModel()#24
sven-ea-assistant wants to merge 2 commits intoatalovesyou:mainfrom
sven-ea-assistant:fix/issue-23-model-prefix-routing

Conversation

@sven-ea-assistant
Copy link

Problem

extractModel() only stripped the hardcoded claude-code-cli/ prefix, so model names like claude-max/claude-sonnet-4 remained prefixed, failed the MODEL_MAP lookup, and fell back to opus.

Root Cause

The regex /^claude-code-cli\// only matched one specific provider prefix.

Changes

src/adapter/openai-to-cli.ts

  • Replace /^claude-code-cli\// with /^[^/]+\// to strip any <provider>/ prefix generically
  • Remove now-redundant hardcoded claude-code-cli/* entries from MODEL_MAP (covered by generic strip)

src/adapter/openai-to-cli.test.ts (new file)

  • 5 tests using Node.js built-in test runner covering:
    1. Unprefixed names (claude-sonnet-4sonnet)
    2. claude-code-cli/ prefix (existing behavior preserved)
    3. claude-max/ prefix (new — the bug fix)
    4. Short aliases (sonnet, opus, haiku)
    5. Unknown model fallback → opus

Test Results

✔ extractModel with unprefixed model names (2.4ms)
✔ extractModel with claude-code-cli/ prefix (0.3ms)
✔ extractModel with claude-max/ prefix (0.2ms)
✔ extractModel with short aliases (0.2ms)
✔ extractModel with unknown model falls back to opus (0.3ms)
ℹ tests 5 | pass 5 | fail 0

Fixes #23

Strip any <provider>/ prefix before MODEL_MAP lookup, not just
the hardcoded 'claude-code-cli/' prefix. This ensures requests with
model names like 'claude-max/claude-sonnet-4' correctly map to
'sonnet' instead of falling back to the opus default.

Changes:
- Replace fixed /^claude-code-cli\// regex with /^[^/]+\// to
  handle any provider prefix generically
- Remove now-redundant hardcoded 'claude-code-cli/*' entries from
  MODEL_MAP (covered by the generic prefix strip)
- Add src/adapter/openai-to-cli.test.ts with 5 tests covering
  unprefixed names, claude-code-cli/ prefix, claude-max/ prefix,
  short aliases, and unknown-model fallback

Fixes atalovesyou#23
…zation

- Add Semaphore + RequestTracker for concurrent subprocess limiting (default 5)
- Wire concurrency module into routes.ts with acquire/release around CLI calls
- Expose active/waiting/capacity stats on /health endpoint
- Fix [object Object] bug: contentToString() handles array content parts
- Add OpenAIContentPart type, support array content in OpenAIChatMessage
- Normalize provider-prefixed model names in extractModel()
- Add --permission-mode bypassPermissions to spawned Claude subprocesses

Closes atalovesyou#23

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
chrisle added a commit to chrisle/claude-max-api-proxy that referenced this pull request Feb 27, 2026
Users can now send large prompts without E2BIG errors, use array-based
content format for multimodal support, properly handle system prompts,
and receive token usage data in streaming responses. Model names with
any provider prefix are now correctly normalized.

Changes:
- Fix array content serialization preventing [object Object] bugs
- Pass prompts via stdin to prevent E2BIG errors with large requests
- Add proper system prompt support via --append-system-prompt flag
- Include usage data in final streaming chunks
- Support any provider prefix in model names (claude-max/, etc.)
- Add CLAUDE_DANGEROUSLY_SKIP_PERMISSIONS env var for service mode
- Update to Claude 4.5/4.6 model support

Incorporates improvements from PRs atalovesyou#12, atalovesyou#13, atalovesyou#16, atalovesyou#24, atalovesyou#27 at
https://github.com/atalovesyou/claude-max-api-proxy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix model routing for claude-max/* prefixed model names

1 participant